package com.mini.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author zhangxiaobin
 * @title: ParamsFilter
 * @description: TODO
 * @date 2020/2/2219:21
 */
@WebFilter(filterName = "ParamsFilter", urlPatterns = "/student/exportAllStudents")
@Slf4j
public class ParamsFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("param filter create success");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String method = (httpServletRequest.getMethod());
        if("GET".equals(method)){
            ParamsRequestWrapper paramsRequestWrapper = new ParamsRequestWrapper(httpServletRequest);
            filterChain.doFilter(paramsRequestWrapper,response);
            return;
        }
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {
        log.info("param filter destroy");
    }
}
